package cn.edu.tcu.controller.admin;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.tcu.bean.AdminBean;
import cn.edu.tcu.dao.admin.DaoFactory;

/**
 * Servlet implementation class AdminInfoQueryServlet
 */
@WebServlet("/AdminInfoQueryServlet")
public class AdminInfoQueryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	List<AdminBean> lstAdmins=null;
	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		 String name=request.getParameter("adminName");
		 if(name==null || name.equals("")){
			 
			 lstAdmins = DaoFactory.getAdminDaoInstance().getAllAdminInfo(0);
		 }else{
			 lstAdmins = DaoFactory.getAdminDaoInstance().searchAdminInfoByName(name);
		 }
		 
		 
		
			//将查询的结果缓存到session中，在前端用el表达式进行解析显示
			request.getSession().setAttribute("lstAdmins", lstAdmins);
			
			//跳转数据保存成功页面
			response.sendRedirect("adminLogined/adminInfoMan/adminInfoQuery.jsp");
		 
	}

}
